home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / alib / csup / commodities_support / argarray.c next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  2.1 KB  |  106 lines

  1. /* argarray.c -- tool types and startup parameters.   */
  2.  
  3. #include <libraries/commodities.h>
  4. #include <workbench/workbench.h>
  5. #include <workbench/startup.h>
  6. #include <exec/memory.h>
  7.  
  8. #include <clib/commodities_protos.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/icon_protos.h>
  11. #include <clib/dos_protos.h>
  12.  
  13. #include <pragmas/commodities_pragmas.h>
  14.  
  15. #include <stdlib.h>
  16.  
  17.  
  18. extern struct Library * __far CxBase;
  19.  
  20.  
  21. ULONG CXLIB_argarray_size;
  22. char  **CXLIB_argarray = 0;
  23. static   struct   DiskObject   *disko = NULL;
  24.  
  25. CxObj *UserFilter(char **tt, STRPTR action_name, STRPTR default_descr);
  26.  
  27.  
  28. char **ArgArrayInit(int argc, char **argv)
  29. {
  30. ULONG             x;
  31. struct WBArg     *arg;
  32. char            **tt = NULL;
  33. struct WBStartup *msg;
  34.  
  35.    if (argc)      /* run from CLI */
  36.    {
  37.       if (argc==1) return(NULL);  /* skip command name */
  38.  
  39.       CXLIB_argarray_size = sizeof(char *)*argc;
  40.       CXLIB_argarray = (char **)AllocVec(CXLIB_argarray_size,MEMF_CLEAR);
  41.       if(! CXLIB_argarray) return(NULL);
  42.  
  43.       for(x=0;x<argc-1;x++)
  44.       {
  45.          CXLIB_argarray[x]=argv[x+1];
  46.       }
  47.       return (CXLIB_argarray);
  48.    }
  49.  
  50.    /* run from WB */
  51.    msg = (struct WBStartup *)argv;
  52.    arg = msg->sm_ArgList;
  53.  
  54.    if (disko = GetDiskObject(arg->wa_Name))
  55.    {
  56.       tt = disko->do_ToolTypes;
  57.    }
  58.  
  59.    return (tt);
  60. }
  61.  
  62.  
  63. VOID ArgArrayDone(VOID)
  64. {
  65.    if(CXLIB_argarray) FreeVec(CXLIB_argarray);
  66.    if (disko) FreeDiskObject(disko);
  67. }
  68.  
  69.  
  70. STRPTR ArgString(char **tt, STRPTR entry,STRPTR defaultstring)
  71. {
  72. STRPTR result;
  73.  
  74.    if (tt && (result = FindToolType(tt,entry)))
  75.       return (result);
  76.  
  77.    return (defaultstring);
  78. }
  79.  
  80.  
  81. LONG ArgInt(char **tt, STRPTR entry, LONG defaultval)
  82. {
  83. STRPTR result;
  84.  
  85.    if (tt && (result = FindToolType(tt,entry)))
  86.    {
  87.        StrToLong(result,&defaultval);
  88.    }
  89.  
  90.    return (defaultval);
  91. }
  92.  
  93.  
  94. CxObj *UserFilter(char **tt, STRPTR action_name, STRPTR default_descr)
  95.  /* tt            - null-terminated (char *(*)[])   */
  96.  /* action_name   - name of your semantic action    */
  97.  /* default_descr - used if user doesn't provide    */
  98. {
  99. STRPTR desc = NULL;
  100.  
  101.    if (tt)
  102.        desc = FindToolType(tt,action_name);
  103.  
  104.    return ( CxFilter((ULONG)(desc? desc: default_descr)));
  105. }
  106.